package com.kedacom.demo.websocket.client;

import java.net.URI;

import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

public class MyWebSocketClientTest {

	public static void main(String[] args) {
		try {
			WebSocketContainer container = ContainerProvider.getWebSocketContainer(); // 获取WebSocket连接器，其中具体实现可以参照websocket-api.jar的源码,Class.forName("org.apache.tomcat.websocket.WsWebSocketContainer");
			String uri = "ws://localhost:8080/demo-websocket/websocket";

			Session session1 = container.connectToServer(MyWebSocketClient.class, new URI(uri)); // 连接会话
			session1.getBasicRemote().sendText("test"); // 发送文本消息
			session1.getBasicRemote().sendText("测试");

			Session session2 = container.connectToServer(MyWebSocketClient.class, new URI(uri)); // 连接会话
			session2.getBasicRemote().sendText("test2"); // 发送文本消息
			session2.getBasicRemote().sendText("测试2");

			session1.close();
			session2.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
